(function(){BX.appLayout={params:{},userSelectorControl:[null,null],userSelectorControlCallback:null,bAccessLoaded:false,_appOptionsStack:[],init:function(a){BX.appLayout.params={firstRun:!!a.firstRun,appHost:a.appHost,appProto:a.appProto,authId:a.authId,authExpires:a.authExpires,refreshId:a.refreshId,formName:a.formName,frameName:a.frameName,isAdmin:!!a.isAdmin,staticHtml:!!a.staticHtml,appId:a.appId,appV:a.appV,appI:a.appI,appSid:a.appSid,memberId:a.memberId,restPath:a.restPath,proto:a.proto,userOptions:a.userOptions,appOptions:a.appOptions};setTimeout(function(){BX.bind(BX(BX.appLayout.params.frameName),"load",function(){BX.addClass(BX("appframe_loading"),"app-loading-msg-loaded");BX.removeClass(this,"app-loading");setTimeout(function(){BX.remove(BX("appframe_loading"))},300)});if(BX.appLayout.params.staticHtml){window[BX.appLayout.params.frameName].src=document.forms[BX.appLayout.params.formName].action}else{document.forms[BX.appLayout.params.formName].submit()}},20)},messageInterface:{refreshAuth:function(a,e){a={action:"access_refresh",sessid:BX.bitrix_sessid()};BX.ajax.loadJSON(location.href,a,function(a){if(!!a["access_token"]){BX.appLayout.params.authId=a["access_token"];BX.appLayout.params.authExpires=a["expires_in"];BX.appLayout.params.refreshId=a["refresh_token"];e({AUTH_ID:BX.appLayout.params.authId,AUTH_EXPIRES:BX.appLayout.params.authExpires,REFRESH_ID:BX.appLayout.params.refreshId})}else{alert("Unable to get new token! Reload page, please!")}})},resizeWindow:function(a,e){var t=BX(BX.appLayout.params.frameName);a.width=a.width=="100%"?a.width:(parseInt(a.width)||100)+"px";a.height=parseInt(a.height);if(!!a.width)t.style.width=a.width;if(!!a.height)t.style.height=a.height+"px";var p=BX.pos(t);e({width:p.width,height:p.height})},setTitle:function(a,e){BX.ajax.UpdatePageTitle(a.title);e(a)},setScroll:function(a,e){if(!!a&&typeof a.scroll!="undefined"&&a.scroll>=0){window.scrollTo(BX.GetWindowScrollPos().scrollLeft,parseInt(a.scroll))}e(a)},getInitData:function(a,e){e({LANG:BX.message("LANGUAGE_ID"),DOMAIN:location.host,PROTOCOL:BX.appLayout.params.proto,PATH:BX.appLayout.params.restPath,AUTH_ID:BX.appLayout.params.authId,AUTH_EXPIRES:BX.appLayout.params.authExpires,REFRESH_ID:BX.appLayout.params.refreshId,MEMBER_ID:BX.appLayout.params.memberId,FIRST_RUN:BX.appLayout.params.firstRun,IS_ADMIN:BX.appLayout.params.isAdmin,INSTALL:BX.appLayout.params.appI,USER_OPTIONS:BX.appLayout.params.userOptions,APP_OPTIONS:BX.appLayout.params.appOptions});BX.appLayout.params.firstRun=false},setUserOption:function(a,e){BX.appLayout.params.userOptions[a.name]=a.value;BX.userOptions.save("app_options","options_"+BX.appLayout.params.appId,a.name,a.value);e(a)},setAppOption:function(a,e){if(BX.appLayout.params.isAdmin){BX.appLayout._appOptionsStack.push([a.name,a.value,e]);BX.defer(BX.appLayout.sendAppOptions)()}},setInstall:function(a,e){BX.userOptions.save("app_options","params_"+BX.appLayout.params.appId+"_"+BX.appLayout.params.appV,"install",!!a["install"]?1:0);e(a)},setInstallFinish:function(a,e){var t={action:"set_installed",v:typeof a.value=="undefined"||a.value!==false?"Y":"N",sessid:BX.bitrix_sessid()};BX.ajax.loadJSON(location.href,t,function(a){var e=window.location.href.replace(/(\?|&)install_finished=[^&]*/gi,"$1");window.location=(e+(e.indexOf("?")==-1?"?":"&")+"install_finished="+(!!a.result?"Y":"N")).replace("&&","&").replace("?&","?")})},selectUser:function(a,e){BX.appLayout.userSelectorControlCallback=e;var t=parseInt(a.mult+0);if(!BX.appLayout.userSelectorControl[parseInt(a.mult+0)]){var p={name:"USER_"+t,onchange:"user_selector_cb_"+parseInt(Math.random()*1e5)};if(t)p.mult=true;window[p.onchange]=BX.appLayout["selectUserCallback_"+t];BX.appLayout.loadControl("user_selector",p,function(p){BX.appLayout.userSelectorControl[t]=BX.PopupWindowManager.create("app-user-popup-"+t,null,{autoHide:true,content:p});if(t){BX.appLayout.userSelectorControl[t].setButtons([new BX.PopupWindowButton({text:BX.message("USER_SELECT"),className:"popup-window-button-accept",events:{click:function(){BX.appLayout.selectUserCallback_1(true)}}})])}BX.appLayout.messageInterface.selectUser(a,e)})}else{if(!BX.appLayout.userSelectorControl[parseInt(a.mult+0)].isShown()){BX.appLayout.userSelectorControl[parseInt(a.mult+0)].show()}BX("USER_"+t+"_selector_content").style.display="block"}},selectAccess:function(a,e){if(!BX.appLayout.bAccessLoaded){BX.appLayout.loadControl("access_selector",{},function(){BX.appLayout.bAccessLoaded=true;BX.defer(BX.appLayout.messageInterface.selectAccess)(a,e)})}else{BX.Access.Init({groups:{disabled:true}});a.value=a.value||[];var t={};for(var p=0;p<a.value.length;p++){t[a.value[p]]=true}BX.Access.SetSelected(t);BX.Access.ShowForm({callback:function(a){var t=[];for(var p in a){if(a.hasOwnProperty(p)){for(var o in a[p]){if(a[p].hasOwnProperty(o)){t.push(a[p][o])}}}}e(t)}})}},selectCRM:function(a,e,t){if(!t){BX.appLayout.loadControl("crm_selector",{entityType:a.entityType,multiple:!!a.multiple?"Y":"N",value:a.value},BX.defer(function(){BX.appLayout.messageInterface.selectCRM(a,e,true)}));return}if(!window.obCrm){setTimeout(function(){BX.appLayout.messageInterface.selectCRM(a,e,true)},500)}else{obCrm["restCrmSelector"].Open();obCrm["restCrmSelector"].AddOnSaveListener(function(a){e(a)})}},reloadWindow:function(){window.location.reload()},imCallTo:function(a){BXIM.callTo(a.userId,!!a.video)},imPhoneTo:function(a){BXIM.phoneTo(a.phone)},imOpenMessenger:function(a){BXIM.openMessenger(a.dialogId)},imOpenHistory:function(a){BXIM.openHistory(a.dialogId)}},receiveMessage:function(a){a=a||window.event;if(a.origin!=BX.appLayout.params.appProto+"://"+BX.appLayout.params.appHost)return;var e=BX.appLayout.split(a.data,":"),t=[];if(e[3]!=BX.appLayout.params.appSid)return;if(e[1])t=JSON.parse(e[1]);if(!!BX.appLayout.messageInterface[e[0]]){var p=e[2];var o=function(a){if(!!p){var e=BX(BX.appLayout.params.frameName).contentWindow;p+=":"+(typeof a=="undefined"?"":JSON.stringify(a));e.postMessage(p,BX.appLayout.params.appProto+"://"+BX.appLayout.params.appHost)}};BX.appLayout.messageInterface[e[0]].apply(BX.appLayout,[t,o])}},split:function(a,e){var t=a.split(e);return[t[0],t.slice(1,t.length-2).join(e),t[t.length-2],t[t.length-1]]},reInstall:function(){BX.appLayout.messageInterface.setInstallFinish({value:false})},loadControl:function(a,e,t){if(!e)e={};e.control=a;e.sessid=BX.bitrix_sessid();BX.ajax({method:"POST",url:location.href,data:e,processScriptsConsecutive:true,onsuccess:BX.defer(t)})},selectUserCallback_0:function(a){var e=BX.util.array_values(a);if(!!e&&e.length>0){BX.appLayout.userSelectorControl[0].close();if(!!BX.appLayout.userSelectorControlCallback)BX.appLayout.userSelectorControlCallback.apply(this,[e[0]])}},selectUserCallback_1_value:[],selectUserCallback_1:function(a){if(a===true){var e=BX.util.array_values(BX.appLayout.selectUserCallback_1_value);BX.appLayout.userSelectorControl[1].close();if(!!BX.appLayout.userSelectorControlCallback)BX.appLayout.userSelectorControlCallback.apply(this,[e])}else{BX.appLayout.selectUserCallback_1_value=a}},hideUpdate:function(a,e){BX.userOptions.save("app_options","params_"+BX.appLayout.params.appId+"_"+BX.appLayout.params.appV,"skip_update_"+a,1);e()},sendAppOptions:function(){if(BX.appLayout._appOptionsStack.length>0){var a=BX.appLayout._appOptionsStack;BX.appLayout._appOptionsStack=[];var e=[];for(var t=0;t<a.length;t++){e.push({name:a[t][0],value:a[t][1]})}var p={action:"set_option",sessid:BX.bitrix_sessid(),options:e};BX.ajax.loadJSON(location.href,p,function(e){for(var t=0;t<a.length;t++){a[t][2](e)}})}}};BX.bind(window,"message",BX.appLayout.receiveMessage)})();
//# sourceMappingURL=script.map.js